﻿/*!
 * 远光ECP平台3.4版本
 * ecp.qzz.ui.grid.js
 * 树表格控件： qzz.ui.qzz
 * @requires qzz.ui.Frame
 */
 
/**
 *ecp按钮与菜单控件命名空间
 *@name qzz.ui
 *@namespace qzz.ui
 */
 define(["qzz.querygrid","qzz.idatepicker","qzz.icombobox","qzz.icombotree",
         "qzz.ibuttonedit","qzz.inumber","qzz.iedit","qzz.iupdown"], function() {
	
	var qzz = window.qzz;
	qzz.space("ui");
	/**
	 * 树表格控件.
	 @class qzz 表格类 

	 @extends qzz.ui.Frame
	 @property {number} rowCount 行数
	 @property {number} colCount 列数
	 @property {number} titleRowCount 标题行数
	 @property {number} gridWidth 表格宽度
	 @property {number} gridHeight 表格高度
	 @property {number} colIndex 当前列标
	 @property {boolean} multiSelect 是否复选
     @property {boolean} virtual 是否懒加载
     @property {qzz.TreeDataSet} dataSet 数据模型
     
	 @example
	     var grid = new qzz.ui.qzz(control, option, metaDataModel);
	 @author qinzhenzhou@ygsoft.com
	 @version 1.0
	 @date 2014-5-29
	
	 */
	qzz.ui.grid = qzz.Class(qzz.ui.querygrid, 
	/**@lends qzz.ui.qzz# */
	{
		/**
		 * 创建.
		 */
		_create:function() {
			this.base();
		    this.className = "Grid";
		    this.logBegin("Grid.create");
		    //编辑对象列表
		    this.editObjects = {};
		    //编辑对象
		    this.editObject;		    
		    //编辑类型
		    this.editType = {
		    		"date":qzz.ui.input.datepicker,
		    		"comboBox":qzz.ui.input.combobox,
		    		"comboTree":qzz.ui.input.combotree,
		    		"buttonEdit":qzz.ui.input.buttonedit,
		    		"number":qzz.ui.input.number,
		    		"text":qzz.ui.input.edit,
		    		"updown":qzz.ui.input.updown
		    }
		    //数据对应编辑类型
		    this.dataType = {
		    		"date":"date",
		    		"enum":"comboBox",
		    		"gldx":"buttonEdit",
		    		"dxfl":"buttonEdit",
		    		"unitcode":"buttonEdit",
		    		"string":"text",
		    		"number":"number",
		    		"money":"number"
		    }
		    if(this.getOption().editType != null) {
		    	for(var key in this.getOption().editType) {
		    		var ck = this.getOption().editType[key];
		    		this.editType[key] = ck;
		    	}
		    }
	    },
	    /**
	     * 渲染.
	     */
	    _render:function() {  
	    	this.base();
	    	var _this = this;
	    	this.popMenu.beginUpdate();
	        var mnen = (this.getBrowser("msie") == true)
	        if(mnen) {
		        //粘贴事件
		        this.popMenu.addMenu("paste", this.getI18n("qzz.paste", "粘贴"), function(){
		        	var text = window.clipboardData.getData('Text');
		        	_this.setFocus();
		        	_this.doPasteData(text);
		        	_this.hasCopy = false;
		        	_this.refresh();
		        }, "Ctrl+V", mnen);
	        }	        
	        //清除事件
	        if(!this.getReadOnly()) {
		        this.popMenu.addMenu("delete", this.getI18n("qzz.clear", "清除"), function(){
		        	_this.clearMark = _this.doClearData();
		        	_this.setFocus();
			    	_this.refresh();
		        }, "Delete", true);
	        }	        
	        //列宽设置
	        this.popMenu.delMenu("qzzFormat");
	        if(this.getOption().colDesign
	        	&& qzz != null
	        	&& qzz.pertain != null
	        		&& typeof qzz.pertain.gridcoldesign == "function") {
	        	if(this.popMenu._popCount > 0) {
	        	    this.popMenu.addMenu("split2", "-");
	        	}
	        	this.popMenu.addMenu("qzzFormat", this.getI18n("qzz.colset", "列设置"), function(){
	    			qzz.pertain.gridcoldesign(_this);
		        });	
	        }
	        this.popMenu.endUpdate();
	    },
	    _loadEditObject:function(met, callBack) {
	    	if(typeof met == "function") {
	    		callBack = met;
	    		met = null;
	    	}
	    	var cms = this.getOption().colModels;
	    	var rqs = [];
	    	var eds = {};
	    	for(var i = 0, len = cms.length; i < len; i++) {
	    		var cm = cms[i];	 
	    		var cmn = "";
				var et = cm.editType;
		        if((et == null || et === "") && cm.dataType != null && cm.dataType !== "") {
		          et = this.dataType[cm.dataType];
		        }
		        if(et == null || et === "") {
		          et = "text";
		        }        
		          if(typeof et == "string" 
		              && this.editType[et] == null) {            
		            switch(et) {
		                case "date" : break;
		                case "comboBox" : break;
		                case "buttonEdit" : break;
		                case "number" : break;
		                case "text" : break;
		                case "updown" : break;    
		                case "radio" : break;
		                case "checkBox" : break;
		                case "onoff" : break;
		                default : cmn = cm.editType; 
		                          cm.outerInput = true;
		                break;
		            }
		            if(eds[cmn] == null) {
		                rqs.push(cmn);
		                eds[cmn] = 1;
		            }
		          } else if(typeof et !== "string"){
		            cm.outerInput = true;
		          }          
		    }
	    	eds = null;
	    	if(rqs.length > 0) {
	    		var that = this;
	    		require(rqs, function(){
	    			//自动把加载的对象添加到edit中
	    			for(var i = 0, len = rqs.length; i < len; i++) {
	    				var mn = rqs[i];
	    				var mo = arguments[i];
	    				var key = mn;
	    				if(that.editType[key] == null) {
	    					that.editType[key] = mo;
	    				}
	    				mo = null;
	    			} //for
	    			rqs = null;
	    		}); //require
	    	}	//if rqs    
	    },
	    /**
	     * 动态加载输入控件.
	     */
	    _createTitle:function() {
	    	this.base();
	    	this._loadEditObject()
	    },
		/**
		 * 区域选择样式调整.
		 */
		_mulSelectStyle:function(col, fcol, prefzCol, cNode, selNode, rowIndex, colIndex, gridReadOnly, colReadOnly, isFocusCell, hasfrozen) {
			if(fcol == null && prefzCol != null && prefzCol.noUse !== true && prefzCol.cellIndex == 0) {
				this.delStyle(prefzCol, "borderRightFocus");
			}
			if(gridReadOnly) {
    			//只读状态
    			if(cNode.recNo === selNode.recNo) {
    				if(colIndex == this.colIndex) {
	    				var css = "gridFocusCell";
	    				if(!this.focus) {
			    			css = "gridNoFocusFocusCell";
			    		}
	    				if(col.className !== css) {
		    				this.setStyle(col, css);
		    				//设置边距   				
		    				if(hasfrozen) {
		    					this.setStyle(fcol, css);	    					
		    				}
	    				}
	    				this.curCell = col;
	    				this.curColIndex = this.colIndex;
	    			} else {
	    				var css = "gridSelRow";
	    			    if(this.focus != true || this.selRect.beginRowNode.getIndex() != this.selRect.endRowNode.getIndex()) {
	    					if(rowIndex % 2 == 1) {
	        					css = "gridReadonly";
	        				} else {
	        					css = "gridCell";
	        				}
	    			    }
	    				if(col.className !== css) {
		    			    this.setStyle(col, css);
	    				}
	    				if(hasfrozen && fcol.className !== css) {
                        	this.setStyle(fcol, css);
	    				}
	    			}
    			} else {
    				if(rowIndex % 2 == 1) {
    					css = "gridReadonly";
    				} else {
    					css = "gridCell";
    				}
    				if(col.className !== css) {
	    				this.setStyle(col, css);	                    
    				}
    				if(hasfrozen && fcol.className !== css) {
                        this.setStyle(fcol, css);
	    		    }
    			}	    			
    		} else {
    			//焦点行
    			if(isFocusCell) {
    				//焦点单元格
    				var css = "gridEditFocusCell";
		    		if(colReadOnly) {
		    			css = "gridFocusCell";
		    		}
		    		if(!this.focus) {
		    			css = "gridNoFocusFocusCell";
		    		}
		    		if(col.className !== css) {
			    		this.setStyle(col, css);
			    		if(hasfrozen) {
			    			this.setStyle(fcol, css);
			    		}		    				
		    		}
		    		//if(!hasfrozen && prefzCol != null) {
    				//	this.addStyle(prefzCol, "borderRightFocus");
    				//}
    				this.curCell = col;
    				this.curColIndex = this.colIndex;
    			} else if(this.mulCellSelect){ 
    				if(colReadOnly){
    					if(col.className !== "gridReadOnly") {
			    			this.setStyle(col, "gridReadonly");
    					}
    					if(hasfrozen && fcol.className !== "gridReadOnly") {
    						this.setStyle(fcol, "gridReadonly");
    					}
		    		} else {
		    			if(col.className !== "gridCell") {
		    				this.setStyle(col, "gridCell");
		    			}
		    			if(hasfrozen && fcol.className !== "gridCell") {
    						this.setStyle(fcol, "gridCell");
    					}
	    			}
                } else if(colReadOnly){
	    			if(col.className !== "gridReadonly") {
		    			this.setStyle(col, "gridReadonly");		    			
	    			}
	    			if(hasfrozen && fcol.className !== "gridReadonly") {
	    				this.setStyle(fcol, "gridReadonly");
    				}
	    		} else {
	    			if(col.className != "gridCell") {
		    			this.setStyle(col, "gridCell");
	    			}
	    			if(hasfrozen && fcol.className != "gridCell") {
	    				this.setStyle(fcol, "gridCell");
    				}
	    		}
    	    }
    		if(this.mulCellSelect
	    	    && cNode.scrIndex <= this.selRect.endRowNode.getIndex()
	    			&& cNode.scrIndex >= this.selRect.beginRowNode.getIndex()
	    				&& colIndex <= this.selRect.endColIndex
	    				    && colIndex >= this.selRect.beginColIndex) {
	    		    //区域选择样式处理
	    			if(this.focus) {		    			
	    				if(isFocusCell) {
	    					if(col.className !== "gridCell") {
		    					this.setStyle(col, "gridCell");
			    				if(hasfrozen) {
			    					this.setStyle(fcol, "gridCell");
			    				}
	    					}
	    				} else {
	    					if(col.className != "gridSelRow") {
		    			        this.setStyle(col, "gridSelRow");
		                        if(hasfrozen) {
		                        	this.setStyle(fcol, "gridSelRow");
			    				}
	    					}
	                        if(this.hasCopy) {
	                        	this.addStyle(col, "cellCopySate");
	                        	if(hasfrozen) {
		                        	this.addStyle(fcol, "cellCopySate");
			    				}		                        	
	                        }
                        }	                        
                        if(colIndex == this.selRect.beginColIndex) {
                        	this.addStyle(col, "borderLeftFocus");
                        	if(hasfrozen) {
	                        	this.addStyle(fcol, "borderLeftFocus");
		    				}// else if(prefzCol != null) {
		    				//	this.addStyle(prefzCol, "borderRightFocus");
		    				//}
                        	//if(fcol == null && prefzCol != null) {
    	                	//	this.addStyle(prefzCol, "borderRightFocus");
    	                	//}
                        }
                        if(colIndex == this.selRect.endColIndex) {
                        	this.addStyle(col, "borderRightFocus");
                        	if(hasfrozen) {
	                        	this.addStyle(fcol, "borderRightFocus");
		    				}
                        }
                        if(colIndex <= this.selRect.endColIndex
    				          && colIndex >= this.selRect.beginColIndex) {
	                        if(cNode.getIndex() == this.selRect.beginRowNode.getIndex()) {
	                        	this.addStyle(col, "borderTopFocus");
	                        	if(hasfrozen) {
		                        	this.addStyle(fcol, "borderTopFocus");
			    				}
	                        }
	                        if(cNode.getIndex() == this.selRect.endRowNode.getIndex()) {
	                        	if(col.style.display === "none" && col.groupCol != null) {
	                        		col = col.groupCol;
	                        	}
	                        	this.addStyle(col, "borderBottomFocus");
	                        	if(hasfrozen) {
	                        		if(fcol.style.display === "none" && fcol.groupCol != null) {
		                        		fcol = fcol.groupCol;
		                        	}
		                        	this.addStyle(fcol, "borderBottomFocus");
			    				}
	                        }
                        }
	                } else {
	                	if(col.className !== "gridNoFocusSelRow") {
                            this.setStyle(col, "gridNoFocusSelRow");
	                        if(hasfrozen) {
	                            this.setStyle(fcol, "gridNoFocusSelRow");
		    			    }
	                	}
                    }
	    			isFocusCell = false;
            }
		},
		//重置编辑输入控件高度
		_refreshEditObjHeight:function(colIndex) {
			var cm = this._getColModel(colIndex);
			if(this.editObject != null && cm.groups === true) {
				var epn = this.editObject.thisWindow.parentNode;
				if(epn != null) {
					var rect = epn.rect || epn.childNodes[0];
					if(rect != null) {
						var eh = this.getNumberValue(rect.style.height);
						this.editObject.setHeight(eh-3);
					}
				}
			}
		},
		//刷新合并列
		_refreshGroups:function(cm, i, j, col, fzCol, pcn, ccn) {
			this.base(cm, i, j, col, fzCol, pcn, ccn);
			this._refreshEditObjHeight(j);
		},
		/**
		 * 刷新树型结构.
		 */
		_refreshTreeCol:function(col, fcol, hasfrozen, cNode, fieldName, text, value, isFocusCell, colReadOnly, cm) {
			//如果是第一列  virtual 虚拟加载    			
    		if(cNode.count > 0 || this.getOption().virtual && cNode.hasExpand != true && cNode.data.isLeaf != true) {
    		    if(hasfrozen) {
    		    	if(fcol.treePoint._option == null) {
        				fcol.treePoint._option = {};
        			}
        			var opt = fcol.treePoint._option;
    		    	if(opt._this == null) {
    		    		opt._this = this;
    		    	}
    		    	opt.node = cNode;
	    		    fcol.treePoint.onclick = this._onTreePointClick;
    		    } else {
    		    	//添加节点加号
        			if(col.treePoint._option == null) {
        				col.treePoint._option = {};
        			}
        			var opt = col.treePoint._option;
        			if(opt._this == null) {
        				opt._this = this;
        			}
        			opt.node = cNode;
        		    col.treePoint.onclick = this._onTreePointClick;
    		    }
	    		if(isFocusCell && !colReadOnly && this.focus && !this.mulCellSelect
    					&& cm.editType != "checkBox" && cm.editType != "radio" && cm.editType != "onoff") {
	    			var editres = true;
	    			//进入编辑状态
	    			if(hasfrozen) {
	    				this._setHtml(fcol.rect.text, "", false);
	    				fcol.onclick = null;
	    				var cw = fcol.rect.parentNode.offsetWidth;
	    				var cl = fcol.levelTd.level - cNode.level;
	    				if(cl != null && cl != 0) {
	    					cw += cl * 16;
	    				}
	    				if(cw <= 0) {
	    					cw = 40;
	    				}
	    				editres = this.setEditObject(fieldName, text, value, fcol.rect, cw - 1);
	    			} else {
	    				this._setHtml(col.rect.text, "", false);
	    				col.onclick = null;
	    				var cw = col.rect.parentNode.offsetWidth;
	    				var cl = col.levelTd.level - cNode.level;
	    				if(cl != null && cl != 0) {
	    					cw += cl * 16;
	    				}
	    				if(cw <= 0) {
	    					cw = 40;
	    				}
	    				editres = this.setEditObject(fieldName, text, value, col.rect, cw - 1);
	    			}
	    			if(editres !== false) {
	    			    this.inputFocus = true;
	    			} else {
    					colReadOnly = true;
    				}
    			} else {		    		
    				if(hasfrozen) {
    					if(fcol.rect.style.display !== "") {
    						this._resetCell(fcol, true);
	    				}	
    				} else {
    					if(col.rect.style.display !== "") {
    		    			this._resetCell(col, true);
        				}
    				}
	    		} //else
	    		//节点加号样式
	    		if(cNode.expanded && cNode.count > 0) {	    			
	    			if(hasfrozen) {
	    				this.setStyle(fcol.treePoint, "component_ui_listview_node_expand");
	    			} else {
	    				this.setStyle(col.treePoint, "component_ui_listview_node_expand");
	    			}		    			
	    		} else {
	    			if(cNode.count == 0) {
	    				cNode.expanded = false;
	    			}	    			
	    			if(hasfrozen) {
	    				this.setStyle(fcol.treePoint, "component_ui_listview_node_collapse");
	    			} else {
	    				this.setStyle(col.treePoint, "component_ui_listview_node_collapse");
	    			}
	    		}
    		} else {    			
	    		if(hasfrozen) {
	    			this.clearStyle(fcol.treePoint);
	    		} else {
	    			this.clearStyle(col.treePoint);
	    		}
    			//不是第一列的数据刷新
    			if(isFocusCell && !colReadOnly && this.focus && !this.mulCellSelect
    					&& cm.editType != "checkBox" 
    						&& cm.editType != "radio" && cm.editType != "onoff") {
    				//进入编辑    				
	    			if(hasfrozen) {
	    				this._setHtml(fcol.rect.text, "", false);
	    			} else {
	    				this._setHtml(col.rect.text, "", false);
	    			}
	    			var editres = true;
    				if(hasfrozen) {
    					fcol.onclick = null;
    					var cw = fcol.rect.parentNode.offsetWidth;
	    				var cl = fcol.levelTd.level - cNode.level;
	    				if(cl != null && cl != 0) {
	    					cw += cl * 16;
	    				}
    					if(cw <= 0) {
	    					cw = 40;
	    				}
    					editres = this.setEditObject(fieldName, text, value, fcol.rect, cw - 1);
    				} else {
    					col.onclick = null;	
    					var cw = col.rect.parentNode.offsetWidth;
	    				var cl = col.levelTd.level - cNode.level;
	    				if(cl != null && cl != 0) {
	    					cw += cl * 16;
	    				}
    					if(cw <= 0) {
	    					cw = 40;
	    				}
    					editres = this.setEditObject(fieldName, text, value, col.rect, cw - 1);
    				}
    				if(editres !== false) {
    				    this.inputFocus = true;
    				} else {
    					colReadOnly = true;
    				}
    			} else {
    				if(hasfrozen) {
    					if(fcol.rect.style.display !== "") {
    						this._resetCell(fcol, true);
	    				}
    				} else {
    					if(col.rect.style.display !== "") {   
    		    			this._resetCell(col, true);
        				}
    				}
	    		} //else
    		} // else
    		if(this.multiSelect) {
    			//复选择处理。
    			if(col.checkBox.isShow() !== true) {
    				col.checkBox.show();
    				col.checkBox.getContainer().parentElement.style.width = "14px";
    				if(hasfrozen) {
    					fcol.checkBox.show();
    					fcol.checkBox.getContainer().parentElement.style.width = "14px";
    				}
    			}    			
    			if(hasfrozen) {
    				if(cNode.enable) {
	    				fcol.checkBox.setDisable(false);
	    			} else {
	    				fcol.checkBox.setDisable(true);
	    			}
    				fcol.checkBox.setCheck(cNode.checkState);
    				if(fcol.checkBox._option == null) {
    					fcol.checkBox._option = {};
    				}
    				var opt = fcol.checkBox._option;
    				if(opt._this == null) {
    					opt._this = this;
    				}
    				opt._cNode = cNode;
    				fcol.checkBox.bind("onClick", this._onTreeCheckBoxClick, true);
    			} else {
    				if(cNode.enable) {
        				col.checkBox.setDisable(false);
        			} else {
        				col.checkBox.setDisable(true);
        			}
    				col.checkBox.setCheck(cNode.checkState);
    				if(col.checkBox._option == null) {
    					col.checkBox._option = {};
    				}
    				var opt = col.checkBox._option;
    				if(opt._this == null) {
    					opt._this = this;
    				}
    				opt._cNode = cNode;
        			col.checkBox.bind("onClick", this._onTreeCheckBoxClick, true);
    			}	    			
    		} else {
    			//单选择处理
    			if(col.checkBox.isShow() === true) { 
    				col.checkBox.hide();
    				col.checkBox.getContainer().parentElement.style.width = "2px";
    				if(hasfrozen) {
    					fcol.checkBox.hide();
    					fcol.checkBox.getContainer().parentElement.style.width = "2px";
    				}
    			}
    		}
    		if(this.treeGrid == false) {
    			if(col.levelTd.style.display != "none") {    				
	    			if(hasfrozen) {
	    				fcol.levelTd.style.display = "none";
	    				fcol.treeTd.style.display = "none";
	    				if(!this.multiSelect) {
	    				    fcol.checkTd.style.display = "none";
	    				}
	    			} else {
	    				col.levelTd.style.display = "none";
		    			col.treeTd.style.display = "none";
		    			if(!this.multiSelect) {
		    			    col.checkTd.style.display = "none";
		    			}
	    			}
    			}
    		} else {
    			var pl = cNode.level * 16 + 4;
	    		this._setNumberValue(col.levelTd, "width", pl);    			
	    		var rw = this._getNumberValue(col.levelDiv.style.width) - pl - this._getNumberValue(col.treeTd.style.width)
	    		    - this._getNumberValue(col.checkTd.style.width) - 4;
	    		if(rw <= 0) {
	    			rw = 40;
	    		}
	    		this._setNumberValue(col.rect, "width", rw);
	    		col.levelTd.level = cNode.level;
	    		if(hasfrozen) {
	    			this._setNumberValue(fcol.levelTd, "width", pl);
	    			this._setNumberValue(fcol.rect, "width", rw);
	    			fcol.levelTd.level = cNode.level;
	    		}
    		}
		},

	    /**
	     * 刷新单元格.
	     * @param {object} row 行元素
	     * @param {object} frow 冻结行元素
	     * @param {object} col 列元素
	     * @param {object} fcol 冻结列元素
	     * @param {number} rowIndex 行序号
	     * @param {number} colIndex 列序号
	     * @param {object} selNode 选择节点
	     * @param {boolean} gridReadOnly 表格只读
	     * @ignore
	     */
	    refreshCell:function(row, frow, col, fcol, prefzCol, rowIndex, colIndex, cNode, selNode, gridReadOnly, noCach) {
	    	var hasfrozen = fcol != null && fcol.noUse !== true; 
	    	var cellText = null;
	    	if(hasfrozen) {
	    		//冻结列及事件
	    		if(fcol._option._this == null) {
	    			fcol._option._this = this;
	    		}
	    		this._bindCellEvent(fcol);
	    		cellText = fcol.rect.text;
	    	} else {
	    		if(col._option._this == null) {
		    	    col._option._this = this;
		    	}
	    		this._bindCellEvent(col);
	    		cellText = col.rect.text;
	    	}
	    	//return 1.0  2ms
	    	if(colIndex == this._colOrder["@INDEX"]) {
	    		//return; //1.1 5ms
	    		if(this.getOption().rownumbers == false) {
	    			if(col.style.width !== "1px") {
		    			col.style.width = "1px";
		    			fcol.style.width = "1px";
	    			}
	    			return;
	    		} else {
	    			if(col.style.width !== "60px") {
		    			col.style.width = "60px";
		    			fcol.style.width = "60px";
	    			}
	    		}
	    		//序号列.
	    		var indexNum = this.dataSet.getIndex();
		    	this.setStyle(fcol, "treeListIndex");
	    		if(this.getOption().pager && !isNaN(this.getPageSize())) {
	    			indexNum += this.getPageSize() * (this.getPageIndex() - 1);
	    		}
	    		this._setHtml(cellText, indexNum, false);
	    		
	    		//绘画背景，和字体颜色
		    	if(typeof this.onCellDraw === "function") {
		    		try {
		    			this.onCellDraw(this.dataSet, fieldName, fcol);
		    		} catch(e) {
		    			this.logInfo("call onCellDraw Error:" + e.message + e.stack);
		    		}		    		
		    	}
		    	this.trigger("onCellDraw_"+fieldName,[this.dataSet, fieldName, fcol]);
	    		
	    	} else if(colIndex === this._colOrder["@MUL"]) {
	    		//return;//1.8
	    		if(col.checkBox == null) return;	    		
    			var fieldName = "@MUL";    			
    			if(hasfrozen) {
    				this.setStyle(fcol, "treeListIndex");
    				this._refreshCheckCell(fcol, fcol.checkBox, cNode.enable == true, cNode, null, fieldName, cNode.checkState);
    				fcol.checkBox.bind("onClick", this._onTreeCheckBoxClick, true);
    				if(fcol.onclick != null) {
	    				fcol.onclick = null;
				    	fcol.ondblclick = null;
    				}
    			} else {
    				this.setStyle(col, "treeListIndex");
        			this._refreshCheckCell(col, col.checkBox, cNode.enable == true, cNode, null, fieldName, cNode.checkState);
        			col.checkBox.bind("onClick", this._onTreeCheckBoxClick, true);
        			if(col.onclick != null) {
    	    			col.onclick = null;
    			    	col.ondblclick = null;
        			}
    			}
    			//绘画背景，和字体颜色
		    	if(typeof this.onCellDraw === "function") {
		    		try {
		    			this.onCellDraw(this.dataSet, fieldName, fcol);
		    		} catch(e) {
		    			this.logInfo("call onCellDraw Error:" + e.message + e.stack);
		    		}		    		
		    	}
		    	this.trigger("onCellDraw_"+fieldName,[this.dataSet, fieldName, fcol]);
	    	} else {
	    		//return; //1.5 24ms
	    		//数据列
	    		var isFocusCell = (cNode.recNo === selNode.recNo && colIndex == this.colIndex);
	    		if(isFocusCell) {	    			
	    			if(hasfrozen) {
	    				this.curCell = fcol;
	    			} else {
	    				this.curCell = col;
	    			}
	    		}
	    		var cm = this._getColModel(colIndex);
	    		//处理隐藏
	    		if(cm.hidden) {
	    			if(col.style.display !== "none") {
			    		col.style.display = "none";
			    		if(hasfrozen) {
			    			fcol.style.display = "none";
			    		}
	    			}
		    		return;
		    	} else if(col.style.display == "none" && cm.groups !== true) {
		    		col.style.display = "";
		    		if(hasfrozen) {
		    			fcol.style.display = "";
		    		}
		    	}
	    		var fieldName = cm.name;
	    		
	    		if(cm.ellipsis !== false && cm.editType != "onoff"
	    			&& cm.editType !== "checkBox" && cm.editType != "radio") {
	    			this.addStyle(cellText, "ellipsis");
	    			cellText.style.lineHeight = (this.rowHeight - 4) + "px";
	    		}
	    		//只读属性
	    		var colReadOnly = gridReadOnly;
	    		if(!colReadOnly) {
	    		    colReadOnly = this.getCellReadOnly(fieldName);
	    		}
	    		var cop = this._getCellOption(fieldName, noCach);
	    		var cellOption = cop.option;
	    		//效验问题
	    		if(cellOption.hasValidate === true 
	  				  && cellOption.validateMessage != null 
	  				    && cellOption.validateMessage !== "" 
	  					  && cellOption.displayText != null 
	  					    && cellOption.displayText !== ""
	  					    	&& (cellOption.value == null || cellOption.value === "")) {
	  				cop.value = cellOption.displayText;
	  			}
	    		cellOption.disabled = this.getBooleanValue(cellOption.disabled, false);	    		
	    		//区域选择样式控制
	    		this._mulSelectStyle(col, fcol, prefzCol, cNode, selNode, rowIndex, colIndex, gridReadOnly, colReadOnly, isFocusCell, hasfrozen);
	    		//return //1.3 22ms
	    		var align = this.getColAlign(fieldName);
	    		var value = cop.value;
		    	var text = cop.text;
		    	//显示值
		    	var title = cellOption.title;
		    	//背景
		    	if(cellOption.bgColor != null) {		    		
		    		if(hasfrozen) {
		    			if(fcol.style.backgroundColor !== cellOption.bgColor) {
		    			    fcol.style.backgroundColor = cellOption.bgColor;
		    			}
		    		} else if(col.style.backgroundColor !== cellOption.bgColor) {
		    			col.style.backgroundColor = cellOption.bgColor;
		    		}	    		
		    	} else {		    		
		    		if(hasfrozen) {
		    			if(fcol.style.backgroundColor !== "") {
		    			    fcol.style.backgroundColor = "";
		    			}
		    		} else if(col.style.backgroundColor !== "") {
		    			col.style.backgroundColor = "";
		    		}
		    	}
		    	//字体
		    	if(cellOption.color != null) {		    		
		    		if(hasfrozen) {
		    			if(fcol.style.color !== cellOption.color) {
		    			    fcol.style.color = cellOption.color;
		    			}
		    		} else if(col.style.color !== cellOption.color) {
		    			col.style.color = cellOption.color;
		    		}	    		
		    	} else {		    		
		    		if(hasfrozen) {
		    			if(fcol.style.color !== "") {
		    			    fcol.style.color = "";
		    			}
		    		} else if(col.style.color !== ""){
		    			col.style.color = "";
		    		}
		    	}
		    	//标注
		    	if(title != null && title !== "") {		    		
		    		if(hasfrozen) {
		    			fcol.setAttribute("title", title);
		    			this.addStyle(fcol, "redInfo");
		    		} else {
		    			col.setAttribute("title", title);
			    		this.addStyle(col, "redInfo");
		    		}	    		
		    	} else {    		
		    		if(hasfrozen) {
		    			fcol.setAttribute("title", "");
		    		} else {
		    			col.setAttribute("title", "");
		    		}	
		    	}
		    	//显示勾稽提示
		    	if(cellOption.GJTitle != null && cellOption.GJTitle !== "") {
		    		
					if(hasfrozen) {
						var otitle = fcol.getAttribute("title");
						if(otitle === "" || otitle == null) {
			    			fcol.setAttribute("title", cellOption.GJTitle);		    		    
			    		} else {
			    			fcol.setAttribute("title", otitle + "\n" + cellOption.GJTitle);
			    		}
						this.addStyle(fcol, "redInfo");
					} else {
						var otitle = col.getAttribute("title");
						if(otitle === "" || otitle == null) {
			    			col.setAttribute("title", cellOption.GJTitle);		    		    
			    		} else {
			    			col.setAttribute("title", otitle + "\n" + cellOption.GJTitle);
			    		}
			    		this.addStyle(col, "redInfo");
					}
		    	}
		    	//显示
		    	if(cm.showHint == true) {
		    		var hintText = text;
		    		if(typeof hintText === "string") {
		    			if(hintText.indexOf("<") != -1) {
		    			    hintText = hintText.replace(/<(\/)?([a-zA-Z]+)( [^<>]+)?>/gi,"");
		    			}
		    			hintText = hintText.trim();
		    		}
		    		if(hintText != null && hintText !== "") {			    		
						if(hasfrozen) {
							fcol.setAttribute("title", hintText + "\n" + fcol.title);
						} else {
							col.setAttribute("title", hintText + "\n" + col.title);
						}
		    		}
		    	}
		    	//return; //1.3 29ms
	    		if((this.getOption().treeKey==null && colIndex == 1 || this.getOption().treeKey==fieldName)
	    				&& this.option.treeGrid != false) {
	    			this._refreshTreeCol(col, fcol, hasfrozen, cNode, fieldName, text, value, isFocusCell, colReadOnly, cm);
	    		} else {
	    			if((cm.editType == "checkBox" || cm.editType == "onoff") && this.isNotEmpty(col.checkBox)) {	    					
	    	    		if(hasfrozen) {
	    	    			this._refreshCheckCell(fcol, fcol.checkBox, cellOption.disabled != true && cm.disabled !== true, cNode, cm, 
	    	    					fieldName, cm.editoptions.check == value);
	    	    			if(fcol.checkBox.hasbind("onClick") !== true) {
	    	    				fcol.checkBox.bind("onClick", this._onCommonCheckBoxClick, true);
	    	    			}
		    				if(fcol.style.textAlign !== align) {
				    		    fcol.style.textAlign = align;
				    		}	
		    				if(cm.editType == "onoff") {
		    					var ctn = fcol.checkBox.onoff.getControl()[0];
		    					if(align == "center") {
		    						ctn.style.marginLeft = "";
		    						ctn.style.margin = "auto";		    						
		    					} else if(align == "right") {
		    						ctn.style.margin = "";
		    						ctn.style.marginLeft = "auto";		    						
		    					} else {
		    						ctn.style.margin = "";
		    						ctn.style.marginLeft = "";
		    					}
		    					fcol.checkBox.onoff.bind("onclick", fcol.checkBox, function(checkBox, ev){
		    						checkBox.click();
		    					}, true);
		    				}
					    } else {
					    	this._refreshCheckCell(col, col.checkBox, cellOption.disabled != true && cm.disabled !== true, cNode, cm, 
		    						fieldName, cm.editoptions.check == value);
		    				if(col.checkBox.hasbind("onClick") !== true) {
		    				    col.checkBox.bind("onClick", this._onCommonCheckBoxClick, true);
		    				}
		    				if(col.style.textAlign !== align) {
				    		    col.style.textAlign = align;
				    		}
		    				if(cm.editType == "onoff") {
		    					var ctn = col.checkBox.onoff.getControl()[0];
		    					if(align == "center") {
		    						ctn.style.marginLeft = "";
		    						ctn.style.margin = "auto";		    						
		    					} else if(align == "right") {
		    						ctn.style.margin = "";
		    						ctn.style.marginLeft = "auto";		    						
		    					} else {
		    						ctn.style.margin = "";
		    						ctn.style.marginLeft = "";
		    					}
		    					col.checkBox.onoff.bind("onclick", col.checkBox, function(checkBox, ev){
		    						checkBox.click();
		    					}, true);
		    				}
					    }
	    	    		if(isFocusCell) {
	    					this.inputFocus = false;
	    				}
	    			} else if(cm.editType == "radio" && this.isNotEmpty(col.radio)) {	    					
	    	    		if(hasfrozen) {
	    	    			this._refreshCheckCell(fcol, fcol.radio, cellOption.disabled != true && cm.disabled !== true, cNode, cm, 
	    	    					fieldName, cm.editoptions.check == value);
	    	    			if(fcol.radio.hasbind("onClick") !== true) {
		    				    fcol.radio.bind("onClick", this._onCommonRadioClick, true);
	    	    			}
			    			if(fcol.style.textAlign !== align) {
				    		    fcol.style.textAlign = align;
			    			}			    			
					    } else {
					    	this._refreshCheckCell(col, col.radio, cellOption.disabled != true && cm.disabled !== true, cNode, cm, 
		    						fieldName, cm.editoptions.check == value);
					    	if(col.radio.hasbind("onClick") !== true) {
		    				    col.radio.bind("onClick", this._onCommonRadioClick, true);
					    	}
		    				if(col.style.textAlign !== align) {
				    		    col.style.textAlign = align;
				    		}
					    }
	    	    		if(isFocusCell) {
	    					this.inputFocus = false;
	    				}
	    			} else if(isFocusCell && !colReadOnly && this.focus && !this.mulCellSelect
	    					&& cm.editType != "checkBox" 
	    						&& cm.editType != "radio" && cm.editType != "onoff") {
	    				//进入编辑
	    				this._setHtml(cellText, "", false);
	    				var editres;
	    				if(hasfrozen) {
	    				    fcol.onclick = null;
	    				    editres = this.setEditObject(fieldName, text, value, fcol.rect);
	    				} else {
	    					col.onclick = null;
	    					editres = this.setEditObject(fieldName, text, value, col.rect);
	    				}
	    				if(editres !== false) {
	    				    this.inputFocus = true;
	    				} else {
	    					colReadOnly = true;
	    				}
	    			} else {	    				
	    				if(hasfrozen) {
	    					if(fcol.rect.style.display !== "") {
	    						this._resetCell(fcol);
		    				}	
	    				} else {
	    					if(col.rect.style.display !== "") {
		    					this._resetCell(col);
		    				}
	    				}
	    				if(isFocusCell) {
	    					this.inputFocus = false;
	    				}
	    			}
	    	    }
	    		if(hasfrozen) {
	    			this.refreshValidate(cm, cNode, value, text, fcol);
	    		} else {
	    		    this.refreshValidate(cm, cNode, value, text, col);
	    		}
	    		//return ;//1.2 46ms
		    	//绘画背景，和字体颜色
		    	if(typeof this.onCellDraw === "function") {
		    		try {
		    			if(hasfrozen) {
		    			    this.onCellDraw(this.dataSet, fieldName, fcol);
		    			} else {
		    				this.onCellDraw(this.dataSet, fieldName, col);
		    			}
		    		} catch(e) {
		    			this.logInfo("call onCellDraw Error:" + e.message + e.stack);
		    		}		    		
		    	}
		    	if(hasfrozen) {
		    	    this.trigger("onCellDraw_"+fieldName,[this.dataSet, fieldName, fcol]);
		    	} else {
		    		this.trigger("onCellDraw_"+fieldName,[this.dataSet, fieldName, col]);
		    	}
		    	/**
		    	 * 字段格式化.
		    	 */
		    	if(this.hasbind("onFormat_" + fieldName)) {
		    		text = this.trigger("onFormat_" + fieldName, [this.dataSet, fieldName, text, value]);
		    	}
		    	//格式化
		    	if(this.hasbind("onGetText_" + fieldName)) {
		    		text = this.trigger("onGetText_" + fieldName, [this.dataSet, fieldName, text, value]);
		    	}
		    	//return;
		    	//return;//1
	    		//设置对齐样式，
	    	    if(!(isFocusCell && !colReadOnly 
	    	    	&& this.focus && !this.mulCellSelect)  
    					&& cm.editType != "checkBox" 
    						&& cm.editType != "radio" && cm.editType != "onoff") {
	    	    	if(this.isNotEmpty(cellOption.link)) {
	    	    		text = "<a href='" + cellOption.link + "'>" + text + "</a>"
	    	    	}	    	    	
	    	    	
    	    		if(hasfrozen) {
		    			if(fcol.style.textAlign !== align) {
			    		    fcol.style.textAlign = align;
		    			}
				    } else if(col.style.textAlign !== align) {
		    		    col.style.textAlign = align;
		    		}
    	    		
    	    		if(cm.link === true && colReadOnly === true) {
                    	if(cellText.al == null) {
                    	    cellText.al = this.createElement("span");
                    	    var _this = this;
                    	    cellText.al.onmouseup = function() {
                    	    	var cn = _this.dataSet.getCurNode();
                    	    	_this.dataSet.beginUpdate();
                    	    	_this.dataSet.select(this._node);
    	    	    			this._node.option[fieldName].linkClick = true;
    	    	    			if(_this.trigger("onLinkClick", [_this, this._fieldName, this._node]) !== false) {
    	    	    			    _this.dataSet.select(cn);
    	    	    			}
    	    	    			_this.dataSet.endUpdate(false);
    	    	    		}                    	    
                    	}
                    	if(cNode.option[fieldName].linkClick === true) {                    	    	
                	    	this.setStyle(cellText.al, "link_visited");
                	    } else {
                    	    this.setStyle(cellText.al, "link");
                	    }
                    	cellText.al.style.display = "";
                    	cellText.al._node = cNode;
                    	cellText.al._fieldName = fieldName;
                    	cellText.al.id = this.dataSet.getIndex();	    	    		
	    	    		this._setHtml(cellText, "");
	    	    		//this._addChild(cellText, cellText.al);
	    	    		cellText.appendChild(cellText.al);
	    	    		this._setHtml(cellText.al, text);
	    	    	} else {	    	    	
	    	    		if(cellText.innerHTML !== text) {
	    	    			this._setHtml(cellText, text, false);
	    	    		}
	    	    	}	    	    	
	    		}
	    	}
	    },

	    /**
	     * 可编辑事件.
	     * @param fieldName 字段名
	     * @param canEdit 可编辑状态
	     * @return 返回状态
	     */
	    canEditing:function(fieldName, canEdit) {
	    	var re = null;
	    	if(typeof this.onCanEditing == "function") {
	    		//执行事件.
	    		try {
	    			re = this.onCanEditing(this, fieldName, canEdit);
	    		} catch(e) {
	    			this.logInfo("[onCanEditing]ERR:" + e.message);
	    		}
	    	}
	    	if(this.hasbind("onCanEditing")) {
	    		re = this.trigger("onCanEditing",[this, fieldName, canEdit]);
	    	}
	    	if(this.isEmpty(re)) {
				re = canEdit;
			}
		    return re;
	    },

	    /**
	     * 执行按钮事件.
	     * @param fieldName 字段名称
	     * @param dataType 数据类型
	     */
	    doButtonEdit : function(fieldName, dataType, value) {
	    	this.focus = false;
	    	var cm = this.getColModel(fieldName);
    		if(typeof this.onButtonEdit == "function") {
    			try {
    				this.onButtonEdit(this.editObject, fieldName, dataType);
    			} catch(e) {
    				this.logInfo("onButtonEdit error " + e.message);
    			}
    		}
    		if(this.hasbind("onButtonEdit")) {
    			this.trigger("onButtonEdit",[this.editObject, fieldName, dataType]);
    		}
	    },
	    decodeTransName:function(cm, value, text){
	    	//如果需要IDNAME转换的话，
			if((this.dataSet.getTransIDName(cm.name) != null || cm.dataType != "number") && text !== value) {
				var tin = {};
				if(cm.multiSelect === true) {
					var idary = [];
					if(typeof value == "string") {
						idary = value.split(",");
					} else if(this.isArray(value)) {
						idary = value;
					}
					var textary = [];
					if(typeof text == "string") {
						textary = text.split(",");
					} else if(this.isArray(text)) {
						textary = text;
					}
					for(var i = 0, len = idary.length; i < len; i++) {
						tin[idary[i]] = textary[i];
					}
				} else {
				    tin[value] = text;
				}
				this.dataSet.addTransIDName(cm.name, tin);
				tin = null;
			}
	    },
	    /**
	     * 提交数据.
	     */
	    post:function() {
	    	if(this.inputFocus && this.editObject != null 
	    			&& (this.editObject._isChanged === true || this.editObject.isChanged != null && this.editObject.isChanged())) {
	    		if(this.dataPost) {
	    			if(typeof this.editObject.setBlur == "function") {
	    				var me = this.mouseEdit;
	    			    this.editObject.setBlur();
	    			    this.mouseEdit = me;
	    			}	    			
	    			this.editObject.focus = false;
	    		}
	    		var value;
	    		if(typeof this.editObject.getValue == "function") {
	    			value = this.editObject.getValue();
	    			if(typeof value == "string") {
	    			    value = this._tagToText(value);
	    			}
	    		}	    		
	    		var text;
	    		if(typeof this.editObject.getText == "function") {
	    		    text = this.editObject.getText();
	    		    if(typeof text == "string") {
	    		        text = this._tagToText(text);
	    		    }
	    		}
	    		var fieldName = this.editObject.fieldName;	    		
	    		var oldValue = this.dataSet.getValue(fieldName);
	    		var op = this.dataSet.getCellOption(fieldName);
	    		var cm = this.getColModel(fieldName);
	    		if(cm.validateSumit !== true && op.validateMessage != null) {
	    			oldValue = op.displayText;
	    		}
	    		var oldText = "";
	    		if(cm.textField != null && cm.textField !== "") {
	    			oldText = this.dataSet.getValue(cm.textField);
	    		}
	    		if(cm.transKey != null && cm.transKey !== "") {
	    			oldText = this.dataSet.getValue(cm.transKey);
	    		}
	    		
	    		var node = this.dataSet.getCurNode();
	    		if(this.hasbind("onSetText_" + fieldName)) {
	    			var vc = this.trigger("onSetText_" + fieldName, [fieldName, node, text]);
	    			if(vc != null) {
	    				value = vc;
	    			}
	    		}
	    		this.dataPost = true;
	    		var updateValue = true;
	    		//控制编辑中的事件.
	    		if(oldValue != value
	    				|| (oldValue == null || oldValue === "") && (value === 0 || value === "0")
	    				   || (oldValue === 0 || oldValue === "0") && (value == null || value === "")) {
	    			if(this.isArray(value)) {
	    				value = value.join(",");
	    			}
	    			//编辑中事件.
	    			if(typeof this.onEditing == "function") {
		    			try {
    		    			if(this.onEditing(cm, oldValue, value, op, node) != false) {
	    		    			if(this.dataSet.setValue(fieldName, value) === true) {
	    		    				if(cm.groups === true) {
	    		    					this._updateGroupValues(fieldName, oldValue, value);
	    		    				}
	    		    				this.decodeTransName(cm, value, text);
	    		    			} else {
	    		    				updateValue = false;
	    		    				//this.dataPost = false;
	    		    			}
	    					    if(this.editObject != null && typeof this.editObject.warnInfo === "string") {
	    					    	this.dataSet.getCellOption(fieldName).title = this.editObject.warnInfo;
	    					    }	
    		    			} else {
    	    					this.dataPost = false;
    	    				}
		    			} catch(e) {
			    			this.logInfo("[onEditing]Error:" + e.message);	    			
			    		}
	    			} else if(this.hasbind("onEditing")) {
	    				if(this.trigger("onEditing",[cm, oldValue, value, op, node]) != false) {	    				
    		    			if(this.dataSet.setValue(fieldName, value) === true){
    		    				if(cm.groups === true) {
    		    					this._updateGroupValues(fieldName, oldValue, value);
    		    				}
    		    				this.decodeTransName(cm, value, text);
    		    			} else {
    		    				updateValue = false;
    		    				//this.dataPost = false;
    		    			}
    					    if(this.editObject != null && typeof this.editObject.warnInfo === "string") {
    					    	this.dataSet.getCellOption(fieldName).title = this.editObject.warnInfo;
    					    }	
		    			} else {
	    					this.dataPost = false;
	    				}
	    			} else {
	    				if(this.dataSet.setValue(fieldName, value) === true) {
	    					if(cm.groups === true) {
		    					this._updateGroupValues(fieldName, oldValue, value);
		    				}
	    					this.decodeTransName(cm, value, text);
	    				} else {
	    					updateValue = false;
	    					//this.dataPost = false;
	    				}
					    if(this.editObject != null && typeof this.editObject.warnInfo === "string") {
					    	this.dataSet.getCellOption(fieldName).title = this.editObject.warnInfo;
					    }
	    			}	    			
		    		//编辑后事件
		    		if(this.dataPost) {
		    			//先合并编辑控件日志
		    			if(this.editObject != null) {
		    				if(typeof this.editObject.mergeChangeLog == "function") {
			    		        this.editObject.mergeChangeLog();
		    				}
		    				this.editObject._isChanged = false;
			    		}
		    			if(updateValue) {
		    				if(cm.textField != null && cm.textField !== "") {
                                this.setValue(cm.textField, text);
                                if(cm.groups === true && oldText != null && oldText !== "") {
    		    					this._updateGroupValues(cm.textField, oldText, text);
    		    				}
                            }
		    				//转换字段
		    				if(cm.transKey != null && cm.transKey !== "") {
                                this.setValue(cm.transKey, text);
                                if(cm.groups === true && oldText != null && oldText !== "") {
    		    					this._updateGroupValues(cm.transKey, oldText, text);
    		    				}
                            }
			    			if(typeof this.onAfterEdit == "function") {			    		
				    			try {
				    				this.onAfterEdit(this.dataSet.getDataType(fieldName), 
				    						fieldName, value, text, cm, node, oldValue);	    				
					    		} catch(e) {
					    			this.logInfo("[onAfterEdit]Error:" + e.message);	    			
					    		}
				    		}
			    			this.trigger("onAfterEdit",[this.dataSet.getDataType(fieldName), 
				    						fieldName, value, text, cm, node, oldValue]);
				    		this.trigger("afterEditCell",[this.getPKeyName(),fieldName,value]);		
		    			}
		    		} else {
		    			//this.editObject.setValue(oldValue);
		    		}
	    		} else if(this.editObject != null) {
	    			if(typeof this.editObject.mergeChangeLog == "function") {
	    			    this.editObject.mergeChangeLog();
	    			}
	    			this.editObject._isChanged = false;
	    		}
	    		if(this.editObject != null && this.dataPost) {
	    			if(typeof this.editObject.setBlur == "function") {
	    			    this.editObject.setBlur();
	    			}
	    			this.editObject.focus = false;
	    			if(typeof this.editObject.mergeChangeLog == "function") {
	    			    this.editObject.mergeChangeLog();
	    			}
	    			this.editObject._isChanged = false;
	    		} else {
	    			this.focus = true;
	    			if(this.editObject != null) {
	    				if(typeof this.editObject.mergeChangeLog == "function") {
		    		        this.editObject.mergeChangeLog();
	    				}
	    				this.editObject._isChanged = false;
		    		}
	    		}
	    		op = null;
	    		cm = null;
	    	}
	    },
		/**
	     * 设置编辑对象.
	     * @param fieldName 字段
	     * @param text 字符串
	     * @param value 值
	     * @param pElement 元素
	     * @param width 宽
	     * @param height 高
	     */
	    setEditObject:function(fieldName, text, value, pElement, width, height) {
	    	if(!this.focus) return;
	    	var cm = this.getColModel(fieldName);
	    	var re = this.editObjects[fieldName];
	    	//处理编辑前事件
	    	var dt = this.dataSet.getDataType(fieldName);
	    	cm.hint = cm.hint === true || (dt == "string" || dt == "number") && cm.hint !== false;
	    	var et = this.dataType[dt];    	
	    	if(this.isNotEmpty(cm.editType)) {
	    		et = cm.editType;
	    	}
	    	if(this._editTypes[fieldName] != null) {
	    		et = this._editTypes[fieldName];
	    	}
	    	var ec = "";
	    	var newEditType = false;
	    	this.dataPost = true;
	    	//获取编辑类型
    		var initJson = null;
    		if(typeof this.onBeforeEdit == "function") {
	    		try {
	    		    //事件返回json对象
	    			initJson = this.onBeforeEdit(dt, fieldName, value, text, cm, this.dataSet.getCurNode());
	    		} catch(e) {
	    			this.logInfo("[onBeforeEdit]Error:" + e.message);	    			
	    		}
	    	}
    		if(this.hasbind("onBeforeEdit")) {
    			initJson = this.trigger("onBeforeEdit", [dt, fieldName, value, text, cm, this.dataSet.getCurNode()]);
    		}
    		var needNew = false;    		
    		//如果事件有返回
    		if(this.isNotEmpty(initJson)) {
				if(this.isNotEmpty(initJson.editType)) {
				    //生成新的dataType
					et = initJson.editType;					
					ec = this.editType[et];
					newEditType = true && et != this._editTypes[fieldName];
					if(ec == null) {
						this._loadEditObject(et);
					}
					needNew = true;
				}
				if(this.isNotEmpty(initJson.value)) {
					value = initJson.value;
				}
				if(this.isNotEmpty(initJson.text)) {
					text = initJson.text;
				}
				//控制是否可以进入编辑
				if(!this.getBooleanValue(initJson.returnValue, true)) {
					return false;
				}
			}
    		var outerInput = false;
    		//获取默认的编辑类型
    		if(this.isEmpty(ec)) {
    			if(typeof et === "string" && cm.outerInput !== true) {
    			    ec = this.editType[et];
    			} else {
    				ec = et;
    				if(typeof et == "string") {
    					ec = this.editType[et];
    				}
    				//外部的对象，默认需要总是创建
    				if(needNew !== false) { 
    					//如果有释放函数则先释放
						if(re != null && re.isComponent && typeof re.destroy == "function") {
						    //re.destroy();
						}
						re = null;    				    
    				}
    				if(cm.outerInput === true) {
    				    outerInput = true;
    				}
    			}
    			this._editTypes[fieldName] = et;
    			//外部控件，再次初始化的时候，没有重新创建。    			
    			newEditType = outerInput;
    		}
    		var needSetParent = true;    		
	    	if(this.isEmpty(re) || newEditType 
	    			|| initJson != null && initJson.data != null) {
	    		if(this.isEmpty(re) || newEditType) {
	    			if(re != null && re.focus === true) {
	    				re.focus = false;
	    			}
	    			cm.cssPrefix = this._cssPrefix;
	    			var fs = this.getNumberValue($(pElement).css("fontSize"), 12);
	    		    if((cm.fontSize == null || cm.fontSize === "") && fs != null) {
	    				cm.fontSize = fs;
	    			}
	    		    //re = new ec(cm);
	    			if(ec != null && typeof ec.createInstance == "function") {
	    				var pn = pElement.parentNode;
	    				this._setHtml(pn, "");
	    				var div = this.createElement("div");
	    				pn.appendChild(div);
	    				pn.appendChild(pElement);
	    				re = ec.createInstance(div, cm);
	    				this.hasSelect = true;
                        this._createEditObject = true;
                        needSetParent = false;
	    			} else if(ec != null) {
	    				var cdom = null;
	    				if(outerInput === true) {
	    					var pn = pElement.parentNode;
		    				this._setHtml(pn, "");
		    				cdom = this.createElement("div");
		    				pn.appendChild(cdom);
		    				pn.appendChild(pElement);
		    				cdom = $(cdom);
		    				this.hasSelect = true;
	                        this._createEditObject = true;
	                        needSetParent = false;
	    				}
	    				re = new ec(cdom, cm);
	    			} else {
	    				return;
	    			}
	    		    re._twoRefresh = false;
	    		    this._editTypes[fieldName] = et;
	    		}	    		
	    		this.editObjects[fieldName] = re;	    		
	    	}
	    	//设置属性	    	
    		if(et == "number") {
    			//数值输入控件
    			re.setSize(cm.length);
    			var ds = cm.precision || cm.dataScale || cm.scale;
    			re.setDataScale(ds);
    			if(this.isNotEmpty(cm.numUnit)) {
    			    re.setNumUnit(cm.numUnit)
    			}
    			if(cm.minValue != null && cm.minValue !== "") {
    				re.setMinValue(cm.minValue);
    			}
    			if(cm.maxValue != null && cm.maxValue !== "") {
    				re.setMaxValue(cm.maxValue);
    			}
    		} else if(et == "date") {
    			//日期编辑控件
    			if(this.isNotEmpty(cm)) {
    				if(cm.showType == "M") {
    					re.setCycType("month");
	    			}
    			}
    			var _this = this;
    			re.onDrop = function(owner) {
    				_this.focus = false;
    				re.mouseEdit = _this.mouseEdit;
    			};
    			re.onHide = function(date) {
    				_this.focus = true;
    				_this.mouseEdit = re.mouseEdit;
    			}
    		} else if(et == "buttonEdit") {
    			
    			//弹出选择控件
    			var _this = this;
    			re.onButtonClick = function() {
    				if(_this.focus) {
    				    _this.doButtonEdit(fieldName, dt, re.getValue());
    				}
    			}
    			var inJson = _this.dataSet.getTransIDName(fieldName);
    			//优先处理事件传回的数据
    			if(this.isNotEmpty(initJson) && this.isNotEmpty(initJson.data)) {
    				inJson = initJson.data;
    			}
    			if(cm.bottonStyle != null) {
    				re.setBottonStyle(cm.bottonStyle);
    			}
    			//名称转换列表初始化
    			if(this.isNotEmpty(inJson)) {
    			    re.setTransIDName(inJson);
    			}
    			inJson = null;
    		} else if(et == "comboBox" || et == "comboTree") {
    			//初始化下拉选择控件
    			var inJson = this.dataSet.getTransIDName(fieldName);
    			//优先处理事件传回的数据
    			if(this.isNotEmpty(initJson) && this.isNotEmpty(initJson.data)) {
    				inJson = initJson.data;
    			}
    			//初始化下拉列表
    			if(this.isNotEmpty(inJson)) {
    				var datas = [];
    				if(this.isArray(inJson)) {
    					datas = inJson;
    				} else {
	    				var i = 0;
	    				
	    			    for(var key in inJson) {
	    			    	var textStr = inJson[key];
	    			    	if(typeof textStr == "object") {
	    			    		textStr = textStr.name;
	    			    	}
	    			    	if(this.isNotEmpty(key)) {
		    			    	datas[i++] = {
		    			    	    "id":key,
		    			    	    "text":textStr||""
		    			    	};
	    			    	}
	    			    }
    				}
    			    re.setItemList(datas);
    			}	
	    		re.keySelect = false;
	    		if(cm != null) {
	    			if(cm.search != null && cm.search !== "") {
	    			    re.setSearch(cm.search);
	    			}
	    			if(cm.more != null && cm.more !== "") {
	    				re.setMore(cm.more);
	    			}
	    		}
    			var _this = this;
    			re.onDrop = function(owner) {
    				_this.focus = false;
    				re.mouseEdit = _this.mouseEdit;
    			};
    			re.onHide = function(index, item) {
    				_this.focus = true;
    				_this.mouseEdit = re.mouseEdit;
    			}
    			re.onSelect = function(index, item) {
    				if(_this.hasbind("onComboBoxSelect")) {
    				    _this.trigger("onComboBoxSelect",[re, fieldName, index, item]);	
    				}
    				if(this.getOption().post === true) {
    					//直接提交
    					_this.post();
    					//刷新表格
    					_this.refresh();
    				}
    			}	
    			re.bind("onMoreClick", function() {
    				if(_this.hasbind("onMoreClick")) {		    				
    					_this.trigger("onMoreClick", [re, this.fieldName]);
    				}
    				//隐藏下拉内容.
					this.popListView.hide();
    			}, true)
    		} else if(et == "text") {
    			if(cm.length != null && cm.length > 0 && typeof re.setSize == "function") {
    			    re.setSize(cm.length);
    			}
    		} else if(et == "updown") {
    			re.option.wheel = false;
    			if(cm.minValue != null && cm.minValue !== "") {
    				re.setMinValue(cm.minValue);
    			}
    			if(cm.maxValue != null && cm.maxValue !== "") {
    				re.setMaxValue(cm.maxValue);
    			}
    		}
    		re.dg = this;
    		re.metaItem = cm;
    		
			var mtl = this.getBooleanValue(cm.multiSelect, false);
			if(mtl && typeof re.setMultiSelect == "function") {
				re.setMultiSelect(mtl);
			}
			if(typeof re.setBorder === "function") {
    		    re.setBorder(0);
			}
			if(typeof re.setDisInput == "function") {
				if(cm.disInput === true) {
					re.setDisInput(true);
					re._readOnly = true;
				}
				if(this.isNotEmpty(initJson)) {
					if(initJson.readOnly === true) {
						re.setDisInput(true);
    					re._readOnly = true;
					} else {
						re.setDisInput(false);
    					re._readOnly = false;
					}
				}    				
			}    			
			if(typeof re.setReadOnly === "function") {    				
				//返回的状态值.
				if(this.isNotEmpty(initJson)) {
					if(initJson.readOnly === true) {
						re.setReadOnly(true);
    					re._readOnly = true;
					} else if(initJson.readOnly === false) {
						re.setReadOnly(false);
    					re._readOnly = false;
					}
				} 
			}

	    	//设置单元格编辑状态
	    	this.editObject = re;
	    	re.fieldName = fieldName;
	    	re.notnull = this.getBooleanValue(cm.notnull, false); 
	    	if(typeof re.beginUpdate === "function") {
	    	    re.beginUpdate();
	    	}
	    	//智能提示
	    	if(cm.hint === true && typeof re.setHintData === "function") {	    		
	    		if(this.hasbind("onHintShow_"+fieldName)) {
	    			var vjs = this.trigger("onHintShow_"+fieldName, [fieldName]);
	    			re.setHintData(vjs);
	    		} else if(this.hasbind("onHintShow")) {
	    			var vjs = this.trigger("onHintShow", [fieldName]);
	    			re.setHintData(vjs);
	    		} else {
			    	this.dataSet.collectFilter(fieldName, function() {
			    		var fjsn = this.filterList[fieldName];
			    		var vjs = [];
			    		for(ckey in fjsn) {
			    			var cv = ckey;
			    			if(dt == "number") {
			    				cv = parseFloat(cv, 10);
			    			}
			    			vjs.push({"id":cv, "text":fjsn[ckey]});
			    		}
			    		re.setHintData(vjs);
			    		vjs = null;
			    		fjsn = null;
			    	});
	    		}
	    	}
	    	//
	    	if(typeof re.setValue === "function") {
	    		if(typeof cm.textField == "string" && cm.textField !== "") {
	    			text = this.dataSet.getValue(cm.textField);
	    		}
	    		//转换字段
	    		if(typeof cm.transKey == "string" && cm.transKey !== "") {
	    			text = this.dataSet.getValue(cm.transKey);
	    		}
	    		//如果是外部控件，输出原来的值.
	    		if(outerInput === true) {
					text = this._textToTag(text);
				}
	    		var sv = {};
	    		var idkey = "id", capkey = "text";
    			if(cm.idkey != null) {
    				idkey = cm.idkey;
    			}
    			if(cm.capkey != null) {
    				capkey = cm.capkey;
    			}
    			sv[idkey] = value;
    			sv[capkey] = text;
	    	    re.setValue(sv);
	    	}
	    	//var pw = pElement.offsetWidth;
	    	//var ph = pElement.offsetHeight;
	    	if(!isNaN(width)) {
	    		if(outerInput === true) {
	    			pw = pw - 2;
	    		}
	    		if(typeof re.setWidth == "function") {
	    		   re.setWidth(width - 1);
	    		}
	    	} else {
	    		var pw = this._getNumberValue(pElement.style.width);
	    		if(outerInput === true) {
	    			pw = pw - 2;
	    		}
	    		if(pw > 0 && typeof re.setWidth == "function") {
	    	        re.setWidth(pw + 5);
	    		}
	    	}	
	    	if(!isNaN(height)) {
	    		if(outerInput === true) {
	    			ph = ph - 3;
	    		}
	    		if(typeof re.setHeight == "function") {
	    		    re.setHeight(height);
	    		}
	    	}else {
	    		var ph = this._getNumberValue(pElement.style.height);
	    		if(outerInput === true) {
	    			ph = ph - 3;
	    		}
	    		if(ph > 0 && typeof re.setHeight == "function") {
	    		    re.setHeight(ph);
	    		}
	    	}
	    	pElement.style.display = "none";
	    	if(needSetParent && typeof re.setParent === "function") {
	    		var pn = pElement.parentNode;
	    		this._setHtml(pn, "");
	    	    re.setParent(pn);
	    	    pn.appendChild(pElement);
	    	}
	    	
	    	re.onEditClick = function(ev) {
	    		this.dg.mouseEdit = true;
	    	}
	    	if(typeof re.setSelectState === "function") {
	    	    re.setSelectState(false);
	    	}
	    	
	    	if(initJson == null || initJson.isChanged !== true) {
		    	if(typeof re.mergeChangeLog === "function") {
		    	    re.mergeChangeLog();
		    	} else {
		    		this.editObject._isChanged = true;
		    	}
	    	}
	    	
	    	//变更事件
	    	if(typeof re.setComAlign === "function") {
	    	    re.setComAlign("right");
	    	}
	    	if(typeof re.endUpdate === "function") {
	    	    re.endUpdate();
	    	}
	    	//var prect = pElement.parentNode.getBoundingClientRect();
	    	if(this._hasScroll !== true) {
	    		if(typeof re.setFocus == "function") {
	    		    re.setFocus();	  
	    		}
	    		re.focus = true;
	    	}
	    	//编辑器渲染后事件.
	    	this.trigger("onAfterEditRender", [cm, this.dataSet.getCurNode(), re]);
	    	cm = null;
	    	return re;
	    },
	    /**
		 * 向右键+TAB键+Enter按键的处理方法
		 * _moveRight方法是内部方法
		 * @name _moveRight
	     * @param {object} ev 事件对象
	     * @param {number} key 键值
		 * @inner 
		 * @ignore		 
		 * @author zengyuangai
		 * @version 1.0
		 * @date 2014-6-30		 
		 */
		_moveRight:function(ev,key) {
			//向右键+TAB键
			this.scrollToFocus();
			var mv = 0
			var cv = this.colIndex - this._colIndexDeff();
			var cm = this.getOption().colModels;			
			var cmLen = cm.length;
			while(cv < cmLen && cm[cv].hidden) {
				mv ++;
				cv ++;
			}
			cm = null;
			var maxIndex = this.colCount - 1;
			if(this.colIndex + mv < maxIndex || ev.shiftKey) {	    			
				if(ev.shiftKey && key == this.keyBoard.RIGHT) {
					if(this.colIndex > this.selRect.beginColIndex) {
						this.selRect.beginColIndex += mv + 1;
					} else if(this.selRect.endColIndex < maxIndex) {
						this.selRect.endColIndex += mv + 1;
					}
					this.refresh(null, true);
				} else {
					this.post();
					if(this.dataPost) {
						this.colIndex += mv + 1;	
						this.selRect.beginColIndex = this.colIndex;
						this.selRect.endColIndex = this.colIndex;
						this.selRect.beginRowNode = this.dataSet.getCurNode();
						this.selRect.endRowNode = this.selRect.beginRowNode;
						this.refresh(null, true);
						this.showFocusCell(this.curCell);						
					} else {
						if(this.inputFocus && this._hasScroll !== true) {
							if(typeof this.editObject.setFocus == "function") {
							    this.editObject.setFocus();
							}
							this.editObject.focus = true;
							this.mouseEdit = false;
							//this.dataPost = true;
						}
					}		    	    		
				}		    			    		
			} else if(this.colIndex + mv == maxIndex){
				this.post();
				if(this.dataPost) {
					var recNo = this.dataSet.getRecNo();
					this.next();
					var Eof = this.dataSet.isEof();
					this.refresh();
					if(!Eof){
						this.listDiv.scrollLeft = 0;
						this.colIndex = 1 + this._colIndexDeff();
						this.selRect.beginColIndex = this.colIndex;
						this.selRect.endColIndex = this.colIndex;
						this.selRect.beginRowNode = this.dataSet.getCurNode();
						this.selRect.endRowNode = this.selRect.beginRowNode;
						this.refresh();						
					}					
				} else {
					if(this.inputFocus && this._hasScroll !== true) {
						if(typeof this.editObject.setFocus == "function") {
						    this.editObject.setFocus();
						}
						this.editObject.focus = true;
					}
				}
			}
			return false;
		},
		/**
		 * 向左键 Shift+TAB键  Shift+Enter按键的处理
		 * _moveLeft方法是内部方法
		 * @name _moveLeft
	     * @param {object} ev 事件对象
	     * @param {number} key 键值
		 * @inner
		 * @ignore
		 * @author zengyuangai
		 * @version 1.0
		 * @date 2014-6-30		 
		 */
		_moveLeft:function(ev,key) {
			this.scrollToFocus();	
			var mv = 0
			var cv = this.colIndex - mv - 2 - this._colIndexDeff();
			var cm = this.getOption().colModels;
			while(cv >= 0 && cm[cv].hidden) {
				mv ++;
				cv = this.colIndex - mv - 2 - this._colIndexDeff();
			}
			cm = null;
			if(this.colIndex > 1 + mv + this._colIndexDeff() || (ev.shiftKey &&  key == this.keyBoard.LEFT) ) {
				if(ev.shiftKey &&  key == this.keyBoard.LEFT) {
					if(this.colIndex < this.selRect.endColIndex) {
						this.selRect.endColIndex -= mv + 1;
					} else if(this.selRect.beginColIndex > 1) {
						this.selRect.beginColIndex -= mv + 1;		    				
					}
					this.refresh(null, true);
				} else {
					this.post();
					if(this.dataPost) {
						this.colIndex -= mv + 1;
						this.selRect.beginColIndex = this.colIndex;
						this.selRect.endColIndex = this.colIndex;
						this.selRect.beginRowNode = this.dataSet.getCurNode();
						this.selRect.endRowNode = this.selRect.beginRowNode;
						this.refresh(null, true);
						this.showFocusCell(this.curCell);
					} else {
						if(this.inputFocus && this._hasScroll !== true) {
							if(typeof this.editObject.setFocus == "function") {
							    this.editObject.setFocus();
							}
							this.editObject.focus = true;
						}
					}		    	    		
				}	
			} else if(this.colIndex + mv == 1 + this._colIndexDeff()){
					this.post();
					if(this.dataPost) {
						var recNo = this.dataSet.getRecNo();
						this.dataSet.prior();
						var bof = this.dataSet.isBof();
						if(this.topNode.recNo == recNo) {
							this.scrollBar.scrollPrior();
						} else {
							this.refresh();
						}
						if(!bof){
							this.listDiv.scrollLeft = this.listDiv.scrollWidth;
							this.colIndex = this.colCount - 1;
							this.selRect.beginColIndex = this.colIndex;
							this.selRect.endColIndex = this.colIndex;
							this.selRect.beginRowNode = this.dataSet.getCurNode();
							this.selRect.endRowNode = this.selRect.beginRowNode;
							this.refresh(null, true);
						}
				} else {
					if(this.inputFocus && this._hasScroll !== true) {
						if(typeof this.editObject.setFocus == "function") {
						    this.editObject.setFocus();
						}
						this.editObject.focus = true;
					}
				}
			}
	    	    return false;
		},
	    /**
	     * 键盘按下
	     * @param ev 事件对象
	     * @param key 键值
	     */
	    doKeyDown:function(ev, key) {
	    	if(this.dataSet.getRecordCount() <= 0) return false;
	    	if(this.inputFocus === true && this.editObject != null 
				    && this.editObject.getPopState() === true) return true;
	    	//Home按键 跳转到第一行
			if(this.keyBoard.HOME == key){
				if(this.mouseEdit){
					return true;
				}
				this.first();
				this.refresh();
				return true;
			} else if(this.keyBoard.END == key){
				if(this.mouseEdit){
					return true;
				}
				//End按键 跳转到最后一行
				this.last();
				this.refresh();
				this.scrollBar.scrollNext();
				return true;
			} else if(this.keyBoard.ESC == key){	
				//ESC 按键处理 恢复数据
				if(this.editObject != null) {
					if(this.dataPost) {
						if(typeof this.editObject.refresh == "function") {
					        this.editObject.refresh();
						}
					} else {
						if(typeof this.editObject.setValue == "function") {
						    this.editObject.setValue(this.dataSet.getDisplay(this.getFieldName()));
						    this.dataPost = true;
						}						
					}
				}
			} else if(ev.shiftKey && this.keyBoard.TAB == key){
				//Shift+tab 按键处理
				this._moveLeft(ev,key);
				return true;
			} else if(ev.ctrlKey || this.priorKey === this.keyBoard.CTRL) {
	    		this.doPaste = false;
	    		if(key == this.keyBoard.C) {
	    			//复制
	    			this.hasCopy = true;
	    			return true;
	    		} else if(key == this.keyBoard.V){
	    			//粘贴
	    			if(this.mulCellSelect || !this.inputFocus) {
	    			   this.copyInput.focus();
	    			} else if(this.inputFocus && this.editObject._readOnly) {
	    				this.copyInput.focus();
	    			}
	    			this.pasteKeyPress = true;
	    			this.doPaste = true;
	    			return true;
	    		}
	    		//Ctrl+A 全选
				if(key == this.keyBoard.A){
						this.colIndex = 1;
			    		this.selRect.beginColIndex = 1;
			    		this.selRect.endColIndex = this.colCount - 1;
			    		this.dataSet.beginUpdate();
			    		this.dataSet.last();
			    		this.selRect.endRowNode = this.dataSet.getCurNode();
			    		this.dataSet.first();
			    		this.selRect.beginRowNode = this.dataSet.getCurNode();	    		
			    		this.dataSet.endUpdate(false);
			    		//点表头时直接进入焦点.
			    		if(!this.focus) {
			    			this.setFocus();
			    		}
			    		this.refresh();

				 }		
				return this.priorKey === this.keyBoard.CTRL;
	    	} else if(key == this.keyBoard.DOWN){
	    		if(this.mouseEdit){
					return true;
				}
	    		if(this.dataSet.getLevel() < 0) {
	    			this.first();
	    			this.mouseEdit = false;
	    			return false;
	    		}
	    		//向下键
	    		if(ev.shiftKey) {
	        		var ri = this.dataSet.getIndex();
	        		var tn = this.dataSet.getCurNode();
	        		this.dataSet.beginUpdate();
	        		this.dataSet.next();
	        		if(ri > this.selRect.beginRowNode.getIndex()) {
	        			this.dataSet.select(this.selRect.beginRowNode);
	        			this.dataSet.next();
	        			this.selRect.beginRowNode = this.dataSet.getCurNode();
	        		} else {
	        			this.dataSet.select(this.selRect.endRowNode);
	        			this.dataSet.next();
	        			this.selRect.endRowNode = this.dataSet.getCurNode();
	        		}
	        		this.dataSet.select(tn);
	        		this.dataSet.endUpdate(false);
	        		tn = null;
	        		this.refresh(null, true);
	    		} else {	
	    			this.post();
	    			if(this.dataPost) {
		    			this.dataSet.beginUpdate();
		    			var tn = this.dataSet.getCurNode();
		    			this.dataSet.next();
		    			this.selRect.beginRowNode = this.dataSet.getCurNode();
	    	    		this.selRect.endRowNode = this.selRect.beginRowNode;
	    	    		this.selRect.beginColIndex = this.colIndex;
	    	    		this.selRect.endColIndex = this.colIndex;
	    	    		this.dataSet.select(tn);
	    	    		this.dataSet.endUpdate(false);
	    	    		tn = null;
		    		    this.next();
	    		    } else {
	    		    	if(this.inputFocus && this._hasScroll !== true) {
	    		    		if(typeof this.editObject.setFocus == "function") {
			    		        this.editObject.setFocus();
	    		    		}
	    		    		this.editObject.focus = true;
			    		}
	    		    }
	    		    
	    		}	    
	    		this.mouseEdit = false;
	    		return false;
	    	} else if(key == this.keyBoard.UP){
	    		if(this.mouseEdit){
					return true;
				}
	    		if(this.dataSet.getLevel() < 0) {
	    			return false;
	    		}
	    		//向上键
	    		if(ev.shiftKey) {
	    			this.dataSet.beginUpdate();
	    			var ri = this.dataSet.getIndex();
	    			var tn = this.dataSet.getCurNode();	        		
	    			if(ri < this.selRect.endRowNode.getIndex()) {
	    				this.dataSet.select(this.selRect.endRowNode);
	    				this.dataSet.prior();
        				this.selRect.endRowNode = this.dataSet.getCurNode();;
        			} else {
        				this.dataSet.select(this.selRect.beginRowNode);
	    				this.dataSet.prior();
        				this.selRect.beginRowNode = this.dataSet.getCurNode();;       				
        			}
	    			this.dataSet.select(tn);
	    			this.dataSet.endUpdate(false);
	        		this.refresh();
	    		} else {
	    			this.post();
	    			if(this.dataPost) {
		    			this.dataSet.beginUpdate();
		    			var tn = this.dataSet.getCurNode();
		    			this.dataSet.prior();	    			
		    			this.selRect.beginRowNode = this.dataSet.getCurNode();
	    	    		this.selRect.endRowNode = this.selRect.beginRowNode;
	    	    		this.selRect.beginColIndex = this.colIndex;
	    	    		this.selRect.endColIndex = this.colIndex;
	    	    		this.dataSet.select(tn);
	    	    		tn = null;
	    	    		this.dataSet.endUpdate(false);
		    			this.prior();	
	    			} else {
	    		    	if(this.inputFocus && this._hasScroll !== true) {
	    		    		if(typeof this.editObject.setFocus == "function") {
			    		        this.editObject.setFocus();
	    		    		}
	    		    		this.editObject.focus = true;
			    		}
	    		    }
	    		}	    	
	    		this.mouseEdit = false;
	    		return false;
	    	} else if(key == this.keyBoard.RIGHT || key == this.keyBoard.TAB) {
	    		//向右键
	    		if(this.mouseEdit && key == this.keyBoard.RIGHT){
					return true;
				}
	    		if(this.dataSet.getLevel() < 0) {
	    			return false;
	    		}
				if(key == this.keyBoard.TAB){
					this.mouseEdit = false;
				}
				this._moveRight(ev,key);
				return false;
	    	} else if(key == this.keyBoard.LEFT){
	    		if(this.mouseEdit){
					return true;
				}
	    		if(this.dataSet.getLevel() < 0) {
	    			return false;
	    		}
	    		//向左键
				this._moveLeft(ev,key);				
				return false;
	    	} else if(key == this.keyBoard.F2) {
	    		if(this.editObject != null && this.editObject.className !== "ComboBox"
	    			&& this.editObject.className !== "BottonEdit") {
	    		    this.mouseEdit = !this.mouseEdit;
	    		}
	    	} else if(ev.shiftKey) {
	    		this.shiftKeyDown = true;
	    	}			
	    },	 
	    /**
	     * 键盘弹起
	     * @param ev 事件对象
	     * @param key 键值
	     */
	    doKeyUp:function(ev, key) {
	    	if(this.overKey) {
	    		this.overKey = false;
	    		return false;
	    	}
	    	//如果弹出状态，则事件无效
	    	if(this.inputFocus === true && this.editObject != null 
				    && this.editObject.getPopState() === true) { 
				return true;
		    }
	    	if(ev.ctrlKey || this.hasCopy || this.doPaste) {
		    	if(key == this.keyBoard.V) {
		    		//粘贴
		    		var value;
		    		if(this.mulCellSelect || !this.inputFocus || this.inputFocus && this.editObject._readOnly) {
		    			value = this.copyInput.value || this.copyInput.tmpValue;
		    			this.copyInput.tmpValue = undefined;
		    		} else {
		    			if(this.editObject != null && typeof this.editObject.getInputValue === "function") {
			    			value = this.editObject.getInputValue() || this.editObject.tmpValue;
			    			if(typeof this.editObject.refresh == "function") {
			    			    this.editObject.refresh();
			    			}
			    			this.editObject.tmpValue = undefined;
		    			}
		    			this.post();
		    		}
		    		if(this.isEmpty(value)) value = "";
		    		this.doPasteData(value);
		    		ev.returnValue = false;
		    		this.doPaste = false;
		    		//return false;
		    	} else if(key == this.keyBoard.C) {
		    		//复制
		    		this.clearMark = null;
		    		this.post();
		    		this.refresh();
		    		//return false;
		    	} else if(key == this.keyBoard.X) {
		    		//剪切
			    	this.clearMark = this.doClearData();
			    	if(this.inputFocus && this.selRect.beginColIndex == this.selRect.endColIndex 
			    			&& this.selRect.beginRowNode.recNo == this.selRect.endRowNode.recNo){
			    		if(typeof this.editObject.setValue == "function") {
			    			var sv = {};
			    			var idkey = "id", capkey = "text";
			    			if(typeof this.editObject.getOption == "function" && this.editObject.getOption().idkey != null) {
			    				idkey = this.editObject.getOption().idkey;
			    			}
			    			if(typeof this.editObject.getOption == "function" && this.editObject.getOption().capkey != null) {
			    				capkey = this.editObject.getOption().capkey;
			    			}
			    			sv[idkey] = "";
			    			sv[capkey] = "";
						    this.editObject.setValue(sv);
			    		}
					}
			    	this.refresh();		    				    		
		    		//return false;
		    	} else if(key == this.keyBoard.Z) {
		    		//回退
		    		if(this.isNotEmpty(this.clearMark)) {
		    		    this.selRect.beginColIndex = this.clearMark.selRect.beginColIndex;
		    		    this.selRect.endColIndex = this.clearMark.selRect.endColIndex;
		    		    this.selRect.beginRowNode = this.clearMark.selRect.beginRowNode;
		    		    this.selRect.endRowNode = this.clearMark.selRect.endRowNode;
		    		    this.dataSet.select(this.selRect.beginRowNode);
		    		    this.colIndex = this.selRect.beginColIndex;
		    		    this.doPasteData(this.clearMark.text);
		    		}
		    	} else if (key == this.keyBoard.PgUp){    //向上翻页
					for(var i = 0; i < this.rowCount - 1; i++) {
						this.scrollBar.scrollPrior();
					}
					return true;
				}else if(key == this.keyBoard.PgDn){    //向下翻页
					for(var i = 0; i < this.rowCount - 1; i++) {
						this.scrollBar.scrollNext();
					}
					return true;
				}
		    	
	    	} else if(key == this.keyBoard.DEL) {
	    		//删除
	    		if(this.mulCellSelect) {
			    	this.clearMark = this.doClearData();
			    	this.refresh();	    
		    	}		    	
	    	} else if(key == this.keyBoard.ENTER){
	    		if(this.dataSet.getLevel() < 0) {
	    			return false;
	    		}	    	
	    		this.mouseEdit = false;
	    		//回车
	    	    this.post();
				if(this.getOption().EnterDown){		    		
		    	    if(this.dataPost) {
		    	    	if(ev.shiftKey){	    	       
				    		var recNo = this.dataSet.getRecNo();
				    		this.dataSet.prior();
							var bof = this.dataSet.isBof();
							if(this.topNode.recNo == recNo) {
								this.scrollBar.scrollPrior();
							} else {
								this.refresh();
							}
							if(bof && this.colIndex > 1){
								this.colIndex = this.colIndex - 1;
								this.last();						
								this.selRect.beginColIndex = this.colIndex;
								this.selRect.endColIndex = this.selRect.beginColIndex;
								this.selRect.beginRowNode = this.dataSet.getCurNode();
								this.selRect.endRowNode = this.selRect.beginRowNode;
								this.scrollBar.scrollNext();
							}
						} else {
							var recNo = this.dataSet.getRecNo();
				    		this.dataSet.next();
				    		this.selRect.beginRowNode = this.dataSet.getCurNode();
							this.selRect.endRowNode = this.selRect.beginRowNode;
				    		var eof = this.dataSet.isEof();
				    		if(!eof && this.bottomNode.recNo == recNo) {
				    		    this.scrollBar.scrollNext();
				    		} else {
				    		    this.refresh();
				    		}
				    		if(eof && this.colIndex < this.colCount - 1){
								this.colIndex = this.colIndex + 1;
								this.first();	//this.last();						
								this.selRect.beginColIndex = this.colIndex;
								this.selRect.endColIndex = this.selRect.beginColIndex;
							}				    		
						}
		    		} else {
	    		    	if(this.inputFocus && this._hasScroll !== true) {
	    		    		if(typeof this.editObject.setFocus == "function") {
			    		        this.editObject.setFocus();
	    		    		}
	    		    		this.editObject.focus = true;
			    		}
	    		    }
		    		return false;	
				}else{
					if(ev.shiftKey){
						this._moveLeft(ev,key);
					}else{
						this._moveRight(ev,key);
					}
					this.setFocus();
				}
	    	} else if(!ev.shiftKey) {
	    		this.shiftKeyDown = false;
	    	}	    
	    	this.pasteKeyPress = false;
	    	this.priorKey = key;
	    },

	    /**
	     * 获取表格只读属性.
	     * @return 返回只读属性
	     */
	    getReadOnly:function() {
	    	var gridReadOnly = this.getOption().cellEdit;
    		if(this.isEmpty(gridReadOnly)) {
    			gridReadOnly = true;
    		} else if(typeof gridReadOnly == "string") {
    			gridReadOnly = this.getBooleanValue(gridReadOnly, true);
    		}
    		gridReadOnly = !gridReadOnly;
    		return gridReadOnly;
	    },
	    /**
	     * 设置表只读.
	     * @param readOnly 只读状态
	     */
	    setReadOnly:function(readOnly) {
	    	var readOnly = readOnly||true;
	    	this.getOption().cellEdit = !readOnly;
	    	this.refresh();
	    },
	    /**
	     * 设置行只读.
	     * @param readOnly 只读状态
	     * @param node 节点
	     */
	    setRowReadOnly:function(readOnly, node) {
	    	var readOnly = readOnly||true;
	    	this.dataSet.setReadOnly(readOnly, node);
	    },
	    /**
	     * 获取单元格只读属性.
	     */
	    getCellReadOnly:function(fieldName, node) {
	        //获取表只读属性
	    	var isReadOnly = this.getReadOnly();	    	
	    	var cn = null;
	    	if(this.isNotEmpty(node)) {
	    	    cn = this.dataSet.getCurNode();	    	    
	    	}
	    	var node = node || this.dataSet.getCurNode();
	    	this.dataSet.select(node);
	    	//row read only
	    	if(this.dataSet.getReadOnly(node)) {
	    		isReadOnly = true;
	    	}
	    	//col read only
	    	if(!isReadOnly) {
	    		var op = this.dataSet.getFieldOption(fieldName);
	    		var cet = true;
	    		if(op != null) {
		    		cet = op.editable;
		    		if(this.isEmpty(cet)) {
		    			 cet = true
		    		}		    	    
	    	    }
	    	    isReadOnly = !this.getBooleanValue(cet, true);
	    	}
	    	//col read only
	    	if(!isReadOnly) {
	    		var op = this.getColModel(fieldName);
	    		var cet = true;
	    		if(op != null) {
		    		cet = op.editable;
		    		if(this.isEmpty(cet)) {
		    			 cet = true
		    		}		    	    
	    	    }
	    	    isReadOnly = !this.getBooleanValue(cet, true);
	    	}
	    	//ext read only
	    	if(!isReadOnly) {
	    		try {
	    	        isReadOnly = !this.canEditing(fieldName, !isReadOnly);
	    		} catch(e) {
	    			this.logInfo("[canEditing]ERROR:" + e.message + e.stack);
	    		}
	    	}
	    	if(this.isNotEmpty(node) && cn != null) {
	    		this.dataSet.select(cn);
	    	}
	    	cn = null;
	    	return isReadOnly;
	    },

	    /**
	     * 执行单元格鼠标按下事件.
	     * @param sender 控件对象
	     * @param ev 事件对象
	     */
	    doCellMouseDown:function(sender, ev) {
	    	this.base(sender, ev);
	    	if(!this.focus) {
	    		this.setFocus();
	    	}
	    },

	    doMouseDown:function(ent) {
	    	this.base(ent);
	    	//拖动横向滚动条用.
	    	this.scrollMouseDown = true;
	    },
	    /**
	     * 执行鼠标弹起事件.
	     * @param ent 事件对象
	     */
        doMouseUp:function(ent) {
	    	this.base(ent);
	    	if(!(this.getMouseButton(ent) == this.mouseType.mtRight && this.hasSelect)) {
		    	if(this.copyInput != null){
		    		this.mulCellSelect = false;
					if(this.dataSet.getRecordCount() > 0) {
		    		    this.mulCellSelect = 
		    			    (this.selRect.beginColIndex < this.selRect.endColIndex || this.selRect.beginRowNode.getIndex() < this.selRect.endRowNode.getIndex());
					}
		    		if(this.mulCellSelect) {
		    		    this.copyInput.select(); 
		    		    this.copyInput.focus();
		    		}
		    	}
	    	}
	    },

	    /**
	     * 设置编辑框的宽度.
	     * @param width 宽度 
	     */
	    _setEditObjectWidth:function(width) {
	    	if(this.inputFocus) {
	        	var nw = width;
	        	var pd = 0;
	        	var fieldName = this.getFieldName(this.colIndex);
	        	if((this.getOption().treeKey==null && this.colIndex == 1 || this.getOption().treeKey==fieldName)
	        			 && this.option.treeGrid != false) {
	        		pd = this._getNumberValue(this.selRow.cells[1].levelTd.style.width, 0) + 20;
	        	}
	        	nw = nw - 10 - pd;
	        	if(nw <= 0) {
	        		nw = 1;
	        	}
	        	if(typeof this.editObject.setWidth == "function") {
	        	    this.editObject.setWidth(nw);	  
	        	}
        	}
	    },
	    /**
	     * 刷新单元格列宽.
	     * @name _refreshCellDivWidth
	     * @param {number} colIndex 列序号
	     * @param {number} newWidth 列宽
	     * @ignore
	     */
	    _refreshCellDivWidth:function(colIndex, newWidth) {
	    	if(colIndex === this._colOrder["@INDEX"] && newWidth < 55) {
	    		return;
	    	}
	    	if(this.colIndex == colIndex) {
	        	this._setEditObjectWidth(newWidth);  
	    	}
	    	this.base(colIndex, newWidth);
	    },   
	    /**
	     * 设置剪贴板.
	     */
	    setClipboard:function(text) {
	    	if (navigator.userAgent.indexOf("MSIE")>0 == true) {	//浏览器为IE
				window.clipboardData.setData("text", text);
				return true;
			} else if (navigator.userAgent.indexOf("Firefox")>0 == true) {		//浏览器为Firefox
				try {
					netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 
				} catch(e) {
//					alert("您的复制操作因设置问题而未生效，请依以下步骤进行设置\n"
//						+ "1. 请在地址栏输入 about:config 并按下enter\n"
//						+ "2. 请于[signed.applets.codebase_principal_support]首选项点击鼠标右键切换值为true\n\n然后重试复制！");
                    alert(this.getI18n("qzz.copyMsg", "因当前浏览器的剪贴板无法控制，请在IE上使用该功能。"));
					return;
				}
				var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 
				if (!clip) {
					clip = null;
					return;
				}	
				var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
				if (!trans) {
					trans = null;
					clip = null;
					return;
				}			
				trans.addDataFlavor('text/unicode'); 
				var str = new Object(); 
				var len = new Object(); 
				var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
				var copytext = text;
				str.data = copytext; 
				trans.setTransferData("text/unicode",str,copytext.length*2); 
				var clipid = Components.interfaces.nsIClipboard; 
				if (!clipid ) {
					trans = null;
					clip = null;
					clipid = null;
					return;
				}				
				clip.setData(trans,null,clipid.kGlobalClipboard);				
				trans = null;
				clip = null;
				clipid = null;
				str = null; 
				len = null; 
				str = null;
				copytext = null;
			}
	    },
	    /**
	     * 执行清除数据
	     */
	    doClearData:function() {
	    	if(this.mulCellSelect) {
	    		var tmpNode = this.dataSet.getCurNode();
	    		this.dataSet.beginUpdate();
	    		this.dataSet.select(this.selRect.beginRowNode);
	    		var copyStr = [];
	    		var colModel = this.option["colModels"];
	    		var ri = 0;
	    		//循环清除数据
	    		while (!this.dataSet.isEof() && this.dataSet.getIndex() <= this.selRect.endRowNode.getIndex()) {
	    			var rowStr = [];
	    			for(var j = this.selRect.beginColIndex - 1,ci = 0; j <= this.selRect.endColIndex - 1; j++) {
	    				var cm = this._getColModel(j + 1);
	    				var fieldName = cm.name;
	    				if(!cm.hidden) {
		    				var cstr = this.dataSet.getDisplay(fieldName);
		    				rowStr[ci++] = cstr === "" ? " ":cstr;
		    				if(!this.getCellReadOnly(fieldName) && cm.notnull !== true && cm.notnull !== "true") {
		    				    this.dataSet.setValue(fieldName, "");
		    				    var ccn = this.dataSet.getCurNode();
		    					//编辑后事件.
		    					if(this.dataPost && typeof this.onAfterEdit == "function") {
		    						try {
		    							var dt = this.dataSet.getDataType(fieldName)
		    							var cm = this.getColModel(fieldName);
		    							this.onAfterEdit(dt, fieldName, "", "", cm, ccn);		    							
		    						} catch(e) {
		    							this.logInfo("[onAfterEdit] error:" + e.message + e.stack);
		    						}
		    					}
		    					if(this.hasbind("onAfterEdit")) {
		    						var dt = this.dataSet.getDataType(fieldName)
	    							var cm = this.getColModel(fieldName);
		    						this.trigger("onAfterEdit", [dt, fieldName, "", "", cm, ccn]);
		    					}
		    					if(this.hasbind("afterEditCell")) {
		    					    this.trigger("afterEditCell",[this.getPKeyName(), fieldName, ""]);
		    					}
		    					if(this.dataSet.getIndex() !== ccn.getIndex()) {
		    						this.dataSet.select(ccn);
		    					}
		    				}
	    				}
	    			}
	    			copyStr[ri++] = rowStr.join("\t");
	    			this.dataSet.next();
	    		}
	    		this.dataSet.select(tmpNode);
	    		this.dataSet.endUpdate(false);
	    		this.trigger("afterClearData",[this]);
	    		return {"text":copyStr.join("\n"),
	    			    "beginColIndex":this.selRect.beginColIndex,
	    			    "endColIndex":this.selRect.endColIndex,
	    			    "beginRowNode":this.selRect.beginRowNode,
	    			    "endRowNode":this.selRect.endRowNode}
	    		tmpNode = null;
	    	} else {
	    		if(this.editObject != null && typeof this.editObject.setValue == "function") {
	    			var sv = {};
	    			var idkey = "id", capkey = "text";
	    			if(typeof this.editObject.getOption == "function" && this.editObject.getOption().idkey != null) {
	    				idkey = this.editObject.getOption().idkey;
	    			}
	    			if(typeof this.editObject.getOption == "function" && this.editObject.getOption().capkey != null) {
	    				capkey = this.editObject.getOption().capkey;
	    			}
	    			sv[idkey] = "";
	    			sv[capkey] = "";
	    			this.editObject.setValue(sv);
	    			this.post();
	    		}
	    	}
	    },
	    /**
	     * 执行粘贴事件.
	     * @param text 字符串
	     */
	    doPasteData:function(text) {
	    	var enc = 0;
	    	if(text.charAt(text.length - 1) == "\n") {
	    		enc = 1;
	    	}
	    	//excel字符中时，有时候中间还带回车，及引号
	    	text = text.replace(/""/g, "&quot;");
	    	text = text.replace(/"([^"]+)"/gi,function(key,$1) {
	    		return $1.replace(/\n/g,"<br/>");
	    	});
	    	var rowAry = text.split("\n");
	    	//var rowAry = text.replace(/(")([^"]+)\1/g,function(k1,k2,k3){return k3.replace(/[\n]/g,"")}).split('\n');
	    	this.dataSet.beginUpdate();
	    	var cn = this.dataSet.getCurNode();
	    	var en = cn;
	    	var oldDatas = [];
	    	var newDatas = [];
	    	var len = rowAry.length;
	    	var refstate = false;
	    	if(len > 1 || rowAry[0].indexOf("\t") !== -1) {
	    		refstate = true;
	    		for(var i = 0; i < len - enc && !this.dataSet.isEof(); i++) {
	    			rowAry[i] = rowAry[i].split("\t");
	    			clen = rowAry[i].length;
	    			var hiddenCount = 0;
	    			var od = {};
	    			od._node = this.dataSet.getCurNode();
	    			var nd = {};
	    			nd._node = od._node;
	    			for(var j = 0; j < clen && j + this.selRect.beginColIndex + hiddenCount < this.colCount; j++) {
	    				var cm = this._getColModel(j + this.selRect.beginColIndex + hiddenCount);
	    				var fieldName = cm.name;
	    				var value = rowAry[i][j];
	    				//去掉字符串中的双引号
	    				if(value != null && value !== "" && typeof value == "string") {
	    				    value = value.replace(/&quot;/g, "\"").replace(/<br\/>/g, "\n");
	    				}
	    				if(cm.hidden) {
	    					hiddenCount ++;
	    					j --;
	    				} else if(!this.getCellReadOnly(fieldName) && cm.disPaste !== true) {
	    					od[fieldName] = this.dataSet.getValue(fieldName);
	    					var ccn = this.dataSet.getCurNode();
	    					if(this.hasbind("onSetText")) {
	    						var cv = this.trigger("onSetText",[value]);
	    						this.dataSet.setValue(fieldName, cv);
	    					} else {
	    						this.dataSet.setDisplay(fieldName, this._tagToText(value), ccn);    						
	    					}
	    				    var vl = this.dataSet.getValue(fieldName);
	    				    nd[fieldName] = vl;    				    
	    				    //编辑后事件.
	    					if(this.dataPost && typeof this.onAfterEdit == "function") {
	    						try {
	    							var dt = this.dataSet.getDataType(fieldName)
	    							var cm = this.getColModel(fieldName);
	    							
	    							this.onAfterEdit(dt, fieldName, vl, value, cm, ccn);		    							
	    						} catch(e) {
	    							this.logInfo("[onAfterEdit] error:" + e.message + e.stack);
	    						}
	    					}
	    					if(this.hasbind("onAfterEdit")) {
	    						var dt = this.dataSet.getDataType(fieldName)
								var cm = this.getColModel(fieldName);
	    						this.trigger("onAfterEdit", [dt, fieldName, vl, value, cm, ccn]);
	    					}
	    					if(this.hasbind("afterEditCell")) {
	    					    this.trigger("afterEditCell",[this.getPKeyName(), fieldName, vl]);
	    					}
	    					if(this.dataSet.getIndex() !== ccn.getIndex()) {
	    						this.dataSet.select(ccn);
	    					}
	    				}
	    			}
	    			oldDatas.push(od);
	    			newDatas.push(nd);
	    			this.selRect.endRowNode = this.dataSet.getCurNode();
	    			if(this.selRect.endColIndex != clen + this.selRect.beginColIndex - 1 + hiddenCount) {
	    				this.selRect.endColIndex = clen + this.selRect.beginColIndex - 1 + hiddenCount;
	    				if(this.selRect.endColIndex > this.colCount - 1) {
							this.selRect.endColIndex = this.colCount - 1;
						}
	    			}
	    			this.dataSet.next();
	    		} //for
	    	} else if(this.editObject != null && this.editObject.inputBox != null) {	    	    
    			//this.editObject.setValue(text);
	    		this.editObject.inputBox.value = text;
	    		//初始化状态.	    		
	    		this.editObject._isChanged = true;	    		
	    		this.editObject.setFocus();
	    	}
    		this.dataSet.select(cn);
    		this.trigger("afterPasteData",[this, oldDatas, newDatas]);
    		this.dataSet.endUpdate(false);
    		if(refstate) {
    		    this.refresh();
    		}
	    },

//	    getChangeSet:function() {
//	    	return this.dataSet.getChangeSet();
//	    },
	    
//	    mergeChangeLog:function(ids) {
//	    	this.dataSet.mergeChangeLog(ids);
//	    },
	    setEditType:function(fieldName, editObj) {
	    	var cm = this.getColModel(fieldName);
	    	cm.editType = editObj;
	    },
	    /**
	     * 清除所有数据.
	     */
	    deleteAll:function() {
	    	this.dataSet.empty(true);
	    	this.dataSet.first();
	    	this.refresh();
	    }	    
	});
	
	/**
	 * 表格控件.
	 */
	_bindRenderFunc("qzzgrid", qzz.ui.grid);
	return qzz.ui.grid;
});		